﻿package mortal.game.view.forging.renderer
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.pack.*;
    import mortal.mvc.core.*;

    public class BackPackItemCellRenderer extends GCellRenderer
    {
        private var _item:PackItem;
        private var _disabledBg:ScaleBitmap;

        public function BackPackItemCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UICompomentPool.getUICompoment(PackItem);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this.addChild(this._item);
            this._disabledBg = UIFactory.bg(0, 0, 40, 40, this, ImagesConst.PackDisable2);
            this._disabledBg.visible = false;
            this.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.ForgingResetTransferPack, this.onResetHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.ForgingResetTransferPack, this.onResetHandler);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:TransferPackData = null;
            super.data = param1;
            if (param1 is TransferPackData)
            {
                _loc_2 = param1 as TransferPackData;
                this._item.itemData = _loc_2.itemData;
                ItemMenuRegister.unRegister(this._item);
                if (_loc_2.isCurrSelData)
                {
                    this._disabledBg.visible = true;
                }
                else
                {
                    this._disabledBg.visible = false;
                }
            }
            else
            {
                this._item.itemData = null;
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:ItemData = null;
            if (event.target is PackItem)
            {
                _loc_2 = (event.target as BaseItem).itemData;
                Dispatcher.dispatchEvent(new DataEvent(EventName.AddTargetEquip, _loc_2));
            }
            return;
        }// end function

        private function onResetHandler(event:DataEvent) : void
        {
            this._disabledBg.visible = false;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._item.dispose(param1);
            this._disabledBg.dispose(param1);
            this._item = null;
            this._disabledBg = null;
            this.removeListeners();
            return;
        }// end function

    }
}
